#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDebug>
#include <QMessageBox>

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    myThread = new MyThread(this);
    connect(myThread, SIGNAL(started()), this, SLOT(slotStarted()));
    connect(myThread, SIGNAL(finished()), this, SLOT(slotFinished()));
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::on_pushButton_clicked()
{
    myThread->start();
}

void MainWindow::on_pushButton_2_clicked()
{
    myThread->terminate();
    myThread->wait();
}

void MainWindow::slotStarted(){
    qDebug() << "子线程已启动";
}
void MainWindow::slotFinished(){
    qDebug() << "子线程已结束";
}

void MainWindow::on_pushButton_3_clicked()
{
    for(int i = 0; i < 12345 * 20; i++){
        qDebug() << "耗时工作" << i;
    }
}

void MainWindow::on_pushButton_4_clicked()
{
    QMessageBox::information(0, "", "其他工作");
}
